

import UIKit

class XSTabBar: UITabBar {
    
    override func layoutSubviews()
    {
        super.layoutSubviews()
        
        let width = UIScreen.mainScreen().bounds.width / 5
        
        let leftFrame = CGRect(x: 0, y: 0, width: width, height: self.bounds.height)
        
        var index = 0
        
        for view in self.subviews
        {
            
            /// 是 UITabBarButton + UIButton
            if (view is UIControl && !(view is UIButton))
            {
                view.frame = CGRectOffset(leftFrame, CGFloat(index) * width, 0)
                
                index += index == 1 ? 2 : 1
            }
        }
        
        compaseBtn.frame = CGRectOffset(leftFrame, CGFloat(2) * width, 0)
    }
    
    lazy var compaseBtn: UIButton = {
        
        let btn = UIButton()
        
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(btn)
        
        return btn
    }()
    
}
